# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=pupy
pkgver=2988.4b78dc58
pkgrel=5
pkgdesc='Opensource, cross-platform (Windows, Linux, OSX, Android) remote administration and post-exploitation tool mainly written in python.'
groups=('blackarch' 'blackarch-automation' 'blackarch-exploitation')
arch=('any')
url='https://github.com/n1nj4sec/pupy'
license=('custom:unknown')
depends=('libffi' 'python' 'tcpdump'
         'python2-rpyc' 'python2-pycryptodome' 'python2-pefile' 'python2-pyaml'
         'python2-rsa' 'python2-netaddr' 'python2-ecdsa' 'python2-paramiko'
         'python2-tinyec' 'python2-psutil' 'python2-netifaces' 'python2-pylzma'
         'python2-colorama' 'python2-mss' 'python2-pyopenssl' 'python2-scapy'
         'python2-pyuv' 'python2-dnslib' 'python2-http-parser'
         'python2-cerberus' 'python2-logutils' 'python2-secretstorage'
         'python2-pygments' 'python2-requests' 'python2-tornado'
         'python2-poster' 'python2-win_inet_pton' 'python2-scandir'
         'python2-msgpack' 'python2-hexdump' 'python2-m2crypto' 'python2-fuse'
         'python2-defusedxml' 'python2-keyboard' 'python2-dateparser'
         'python2-puttykeys' 'python2-pyelftools' 'python2-filemagic'
         'python2-xattr' 'python2-flake8' 'python2-flake8-per-file-ignores'
         'python2-pypykatz' 'python2-tzlocal' 'python2-regex' 'python2-pyaes'
         'impacket')
makedepends=('git' 'wget')
options=('!strip')
source=("git+https://github.com/n1nj4sec/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

prepare() {
  cd $pkgname

  git submodule update --init --recursive

  wget -c \
    https://github.com/n1nj4sec/pupy/releases/download/latest/payload_templates.txz

  tar -xvf payload_templates.txz
  mv payload_templates/* pupy/payload_templates/
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin/"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  cp -a --no-preserve=ownership "$pkgname"/* "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/pupygen" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python2 pupygen.py "\$@"
EOF
  chmod +x "$pkgdir/usr/bin/pupygen"

  cat > "$pkgdir/usr/bin/pupysh" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python2 pupysh.py "\$@"
EOF
  chmod +x "$pkgdir/usr/bin/pupysh"
}

